﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class tools_Probe : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Expires = 0;
        Response.CacheControl = "no-cache";
        if (!Page.IsPostBack)
        {
            //取得页面执行开始时间
            DateTime stime = DateTime.Now;

            int build, major, minor, revision;
            build = Environment.Version.Build;
            major = Environment.Version.Major;
            minor = Environment.Version.Minor;
            revision = Environment.Version.Revision;

            name.Text = Server.MachineName;
            ip.Text = Request.ServerVariables["LOCAL_ADDR"];
            domain.Text = Request.ServerVariables["SERVER_NAME"];
            port.Text = Request.ServerVariables["SERVER_PORT"];
            ontime.Text = DateTime.Now.ToString();
            lan.Text = Request.ServerVariables["HTTP_ACCEPT_LANGUAGE"];
            cpuqty.Text = System.Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS");
            cpumore.Text = System.Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE");
            system.Text = Environment.OSVersion.ToString();
            dotnet.Text = ".NET CLR  " + major + "." + minor + "." + build + "." + revision;

            user.Text = Environment.UserName;
            sysdir.Text = System.Environment.GetEnvironmentVariable("windir");
            systmp.Text = System.Environment.GetEnvironmentVariable("TEMP");
            mem.Text = (Environment.WorkingSet / 1024 / 1024).ToString() + " MB";
            atdomain.Text = System.Environment.GetEnvironmentVariable("USERDOMAIN");


            SSL.Text = Request.ServerVariables["HTTPS"];
            CGI.Text = Request.ServerVariables["GATEWAY_INTERFACE"];
            IIS.Text = Request.ServerVariables["SERVER_SOFTWARE"];
            timeout.Text = Server.ScriptTimeout.ToString();
            runtime.Text = Math.Round((decimal)(Environment.TickCount / 600 / 60)) / 100 + " 小时";
            path.Text = Request.ServerVariables["APPL_PHYSICAL_PATH"];
            pathinfo.Text = Request.ServerVariables["PATH_TRANSLATED"];


            //组件支持验证代码
            this.check("MSWC.AdRotator", adrot);
            this.check("MSWC.BrowserType", brow);
            this.check("MSWC.NextLink", next);
            this.check("MSWC.Tools", tool);
            this.check("AMSWC.Status", stat);
            this.check("MSWC.Counters", coun);
            this.check("IISSample.ContentRotator", cont);
            this.check("IISSample.PageCounter", pagec);
            this.check("MSWC.PermissionChecker", perm);
            this.check("Scripting.FileSystemObject", fso);
            this.check("ADODB.RecordSet", adodb);

            this.check("SoftArtisans.FileUp", saup);
            this.check("SoftArtisans.FileManager", arup);
            this.check("LyfUpload.UploadFile", lyup);
            this.check("Persits.Upload", aspup);
            this.check("W3.Upload", w3up);

            this.check("JMail.SMTPMail", jmail);
            this.check("CDONTS.NewMail", cdon);
            this.check("Persits.MailSender", pers);
            this.check("SMTPsvg.Mailer", smtp);
            this.check("dkQmail.Qmail", qmail);
            this.check("Geocel.Mailer", mailer);
            this.check("iismail.iismail.1", iismail);
            this.check("SmtpMail.SmtpMail.1", smtpmail);

            this.check("SoftArtisans.ImageGen", saimg);
            this.check("W3Image.Image", w3img);


            //取得页面执行结束时间
            DateTime etime = DateTime.Now;
            //计算页面执行时间
            timerun.Text = ((etime - stime).TotalMilliseconds).ToString() + "毫秒";

            //100万次相加循环测试
            DateTime ontime1 = DateTime.Now;
            int sum = 0;
            for (int i = 1; i <= 10000000; i++)
            {
                sum = sum + i;
            }
            DateTime endtime1 = DateTime.Now;
            timetol.Text = ((endtime1 - ontime1).TotalMilliseconds).ToString() + "毫秒";

            //100万次开平方测试
            DateTime ontime2 = DateTime.Now;
            long k = 2;
            for (int a = 1; a < 1000000; a++)
            {
                k = k * k;
            }
            DateTime endtime2 = DateTime.Now;
            timekai.Text = ((endtime2 - ontime2).TotalMilliseconds).ToString() + "毫秒";


        }
    }
    bool isobj(string obj)
    {
        try
        {
            object meobj = Server.CreateObject(obj);
            return (true);
        }
        catch
        {
            return (false);
        }
    }

    void check(string obj, Label sup)
    {
        string yes = "<font class=fonts1><b>√</b></font>";
        string no = "<font color=red><b>×</b></font>";
        try
        {
            object claobj = Server.CreateObject(obj);
            sup.Text = yes;
        }
        catch
        {
            sup.Text = no;
        }
    }

    //自定义组件查询
    public void sub(Object Sender, EventArgs e)
    {
        string classobj = classname.Text;
        if (isobj(classobj))
        {
            classinfo.Text = "检测结果：支持组件" + classobj;
        }
        else
        {
            classinfo.Text = "检测结果：不支持组件" + classobj;
        }
    }
}